package wwl.lsf;

import wwl.lsf.base.ListNode;

import java.util.List;

/**
 * @Title
 * @Author wangwenliang
 * @Date 2021/5/25
 * @Description
 */
public class 两两交换链表中的节点 {

    public ListNode swapPairs(ListNode head) {

        if (head == null || head.next == null) {
            return head;
        }

        ListNode newHead = head.next;

        head.next = swapPairs(newHead.next);

        newHead.next = head;

        return newHead;

    }

    public ListNode xunhuan(ListNode head) {


        ListNode yajiedian = new ListNode(0, head);
        ListNode temp = yajiedian;
        while (temp.next != null && temp.next.next != null) {


            ListNode node1 = temp.next;
            ListNode node2 = temp.next.next;
            temp.next = node2;
            node1.next = node2.next;
            node2.next = node1;
            temp = node1;

        }


        return yajiedian.next;

    }
}
